<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            录入不合格数量
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码内容表ID</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="id" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货单号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="consignment" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">箱号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="boxnum" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">数量</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="qty" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">不合格数量</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="badQty">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <p>
            <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>
        </p>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化查询明细数据和下拉框下拉框
    apiready = function() {

        //条码表ID（SS_TMCONTENT）
        var id = api.pageParam.id;
        //箱号
        var boxnum = api.pageParam.boxnum;
        //物料号
        var mrlCode = api.pageParam.mrlCode;
        //数量
        var qty = api.pageParam.qty;
        //不合格数量
        var badQty = api.pageParam.badQty;
        //发货单号
        var consignment = api.pageParam.consignment;
        doInit(id, boxnum, mrlCode, qty, badQty, consignment);
    }

    //初始化查询
    function doInit(id, boxnum, mrlCode, qty, badQty, consignment) {
        //id赋值
        $("#id").val(id);
        //发货单号
        $("#consignment").val(consignment);
        //箱号
        $("#boxnum").val(boxnum);
        //物料号
        $("#mrlCode").val(mrlCode);
        //数量
        $("#qty").val(qty);
        //批次号
        $("#badQty").val(badQty);
    }

    //保存
    function save() {
        //取ID
        var id = $("#id").val();
        //数量
        var qty = $("#qty").val();
        //不合格
        var badQty = $("#badQty").val();

        //不合格数大于0验证
        if (parseInt(badQty) <= 0) {
            api.toast({
                msg: '不合格数量必须大于0！',
                duration: 3000
            });
            return;
        }

        //不合格数量不能大于合格数
        if (parseInt(badQty) > parseInt(qty)) {
            api.toast({
                msg: '不合格数量不能大于' + qty + '！',
                duration: 3000
            });
            return;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/updateTmContentBadQty";
        var data = {
            values: {
                id: id,
                qty: qty,
                badQty: badQty,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == "0") {

                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    var consignment = $("#consignment").val();
                    api.closeWin({});

                    //刷新原界面
                    api.execScript({
                        name: 'uwmYqgyReceipt_badQty',
                        script: 'refresh("' + consignment + '")'
                    });

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
